<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<?php
	include_once("include/config.php");
	include_once("include/auth.lib.php");
?>

<html>
	<head>
		<title><?php echo TITLE ?></title>
		<link href="lib/jqueryui/development-bundle/themes/base/jquery.ui.all.css" rel="stylesheet" type="text/css"/>
		<link href="judoinvorio.css" rel="stylesheet" type="text/css"/>
		
		<script src="lib/jquery.js"></script>
		<script src="lib/jquery-ui.min.js"></script>
		
		<link rel="stylesheet" type="text/css" href="flexigrid/css/flexigrid/flexigrid.css">
		<script type="text/javascript" src="flexigrid/flexigrid.js"></script>
		
		<script>
			$(document).ready(function() {
				$("input:button, input:reset, input:submit").button();
			});
			
			function show(value) {
				if (value == 'palestre') {
					$('#box-atleti').hide('slow');
					$('#box-palestre').show('slow');
					$('#grid-palestre').flexReload();
				} else if (value == 'atleti') {
					$('#box-atleti').show('slow');
					$('#box-palestre').hide('slow');
					$('#grid-atleti').flexReload();
				}				
			}	
			
			function onFilterPalestre() {
				$('#palestre-result').html('Totale: 0');			
				$('#grid-palestre').flexOptions({qtype: $('#palestre-select').val(), query: $('#palestre-filter').val()}).flexReload();
			}			
			
			function onFilterAtleti() {
				$('#atleti-result').html('Totale: 0');			
				$('#grid-atleti').flexOptions({qtype: $('#atleti-select').val(), query: $('#atleti-filter').val()}).flexReload();
			}
		</script>		
  
	</head>
	<body>
	
<?php

	echo "
		<input type='button' value='Palestre' onclick='show(\"palestre\");' />
		<input type='button' value='Atleti' onclick='show(\"atleti\");'/>		
	";
?>
	<div id="box-palestre" class="box-centered">
		Cerca per 
		<select id="palestre-select" name="field-name">
			<option value="nome">Nome palestra</option>
			<option value="istruttore">Nome istruttore</option>
			<option value="email">Email</option>
		</select>
		<input type="text" id="palestre-filter" value="" />&nbsp;&nbsp;
		<input type="button" value="Cerca" onclick="onFilterPalestre();" />&nbsp;&nbsp;&nbsp;&nbsp;
		<span id="palestre-result" style="font-weight:bold;">Totale: </span>
		<br/><br/>
		<table id="grid-palestre" style="display:none"></table>
		<br/>		
		<table>
			<tr><td>
				<form action="export-palestre.php" method="GET" target="_blank"> 
					<input type="submit" value="Esporta Xml" />
				</form>
			</td><td>
				<form action="export-palestre-xls.php" method="GET" target="_blank"> 
					<input type="submit" value="Esporta Excel" />
				</form>		
			</td></tr>
		</table>
	</div>
	
	<div id="box-atleti" class="box-centered" style="display:none">
		Cerca per 
		<select id="atleti-select" name="field-name">
			<option value="cognomenome">Cognome o nome</option>
			<option value="nome">Nome palestra</option>
		</select>
		<input type="text" id="atleti-filter" value="" />&nbsp;&nbsp;
		<input type="button" value="Cerca" onclick="onFilterAtleti();" />&nbsp;&nbsp;&nbsp;&nbsp;
		<span id="atleti-result" style="font-weight:bold;">Totale: </span>&nbsp;&nbsp;&nbsp;&nbsp;
		<br/><br/>
		<table id="grid-atleti" style="display:none"></table>
		<br/>		
		<table>
			<tr><td>
				<form action="export-atleti.php" method="GET" target="_blank"> 
					<input type="submit" value="Esporta Xml" />
				</form>
			</td><td>
				<form action="export-atleti-xls.php" method="GET" target="_blank"> 
					<input type="submit" value="Esporta Excel" />
				</form>		
			</td></tr>
		</table>
	</div>
	
	<script type="text/javascript">
		
		$("#grid-palestre").flexigrid(
			{
				url: 'admin-palestre-list.php',
				dataType: 'json',
				colModel : [
					{display: 'ID', name: 'id', sortable: true, align: 'center', hide: true},
					{display: 'Palestra', name: 'nome', width: 200, sortable: true, align: 'left'},
					{display: 'Codice federale', name: 'codice_federale', width: 100, sortable: true, align: 'left'},
					{display: 'Istruttore', name: 'istruttore', width: 300, sortable: true, align: 'left'},
					{display: 'Email', name: 'categoria', width : 250, sortable: true, align: 'left'},
					{display: 'Sito', name: 'peso', width : 200, sortable: true, align: 'right'}
				],
				sortname: "cognomenome",
				sortorder: "asc",
				usepager: false,
				title: 'Palestre',
				useRp: false,
				rp: 15,
				showTableToggleBtn: false,
				singleSelect: true,
				onSuccess: function() {
					$('#palestre-result').html('Totale: ' + this.total);
				}
			}
		);
		
		$("#grid-atleti").flexigrid(
			{
				url: 'admin-atleti-list.php',
				dataType: 'json',
				colModel : [
					{display: 'ID', name: 'id', sortable: true, align: 'center', hide: true},
					{display: 'ID palestra', name: 'id_palestra', width: 100, sortable: true, align: 'center', hide: true},
					{display: 'Palestra', name: 'nome_palestra', width: 100, sortable: true, align: 'left'},
					{display: 'Cognome e nome', name: 'cognomenome', width: 300, sortable: true, align: 'left'},
					{display: 'Categoria', name: 'categoria', width : 250, sortable: true, align: 'left'},
					{display: 'Peso', name: 'peso', width : 50, sortable: true, align: 'right'}
				],
				sortname: "cognomenome",
				sortorder: "asc",
				usepager: false,
				title: 'Atleti',
				useRp: false,
				rp: 15,
				showTableToggleBtn: false,
				singleSelect: true,
				onSuccess: function() {
					$('#atleti-result').html('Totale: ' + this.total);
				}
			}
		);
	</script>

	</body>
</html>
